import axios from "axios"
import qs from "qs"
// 引入instance实例
const instance = axios.create({
  baseURL: 'http://123.207.32.32:8000/api/v1/',
  timeout: 1000 * 60,
});
instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
// 配合qs.string
// 请求拦截
instance.interceptors.request.use(config => {
  //可以放请求token
  return config
}, err => {
  return Promise.reject(err)
})
// 响应拦截
instance.interceptors.response.use(response => {
  return response.data
}, err => {
  return Promise.reject(err)
})

export default new class Request {
  get(url, params = {}) {
    return new Promise((resolve, reject) => {
      // axios异步请求
      instance.get(url, { params }).then(data => resolve(data)).catch(err => reject(err))
    })
  }
  post(url,params={}){
    return new Promise((resolve,reject)=>{
      instance.post(url,qs.stringify(params)).then(data=>resolve(data)).catch(err=>reject(err))
    })
  }

 
}
